﻿#region Copyrights Notice
//©2010 Microsoft Corporation. All rights reserved.
#endregion

#region usings
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.ServiceModel;
using Microsoft.InformationSecurity.CISF.SecurityPortal.Business.Entities;
using Microsoft.InformationSecurity.CISF.SecurityPortal.Services.Contracts;
using Microsoft.InformationSecurity.CISF.SecurityPortal.Business.WidgetFacade;
#endregion

namespace Microsoft.InformationSecurity.CISF.SecurityPortal.Services
{
    /// <summary>
    /// Implementation for Portal Service Interface
    /// </summary>
    [ServiceBehavior(UseSynchronizationContext = false,
    ConcurrencyMode = ConcurrencyMode.Multiple,
    InstanceContextMode = InstanceContextMode.PerCall)]
    public class PortalService : IPortalServiceContract
    {
        public PortalService()
        {
        }

        public List<Widget> GetWidgetList(string userName)
        {
            try
            {
                WidgetFacade wfacade = new WidgetFacade(userName);
                return wfacade.GetWidgetList();
            }
            catch (Exception ex)
            {
                //Console.WriteLine(ex.Message);
                return null;
            }
        }

        public Boolean IsRegisteredUser(string userName)
        {
            try
            {
                WidgetFacade wfacade = new WidgetFacade(userName);
                return wfacade.IsUserRegistered();
            }
            catch (Exception ex)
            {
                //Console.WriteLine(ex.Message);
                return false;
            }
        }

        public WidgetSetup LoadWidgetSetup(string userName)
        {
            try
            {
                WidgetFacade wfacade = new WidgetFacade(userName);
                return wfacade.LoadWidgetSetup();
            }
            catch (Exception ex)
            {
                //Console.WriteLine(ex.Message);
                return null;
            }
        }

        public WidgetSetup GetWidgetSetup(string userName)
        {
            try
            {
                WidgetFacade wfacade = new WidgetFacade(userName);
                return wfacade.GetWidgetSetup();
            }
            catch (Exception ex)
            {
                //Console.WriteLine(ex.Message);
                return null;
            }
        }

        public WidgetSetup ResetWidgetSetup(string userName)
        {
            try
            {
                WidgetFacade wfacade = new WidgetFacade(userName);
                return wfacade.ResetWidgetSetup();
            }
            catch (Exception ex)
            {
                //Console.WriteLine(ex.Message);
                return null;
            }
        }

        public WidgetSetup UpdateWidgetSetup(string userName, WidgetSetup _oldSetup, WidgetSetup _newSetup)
        {
            try
            {
                WidgetFacade wfacade = new WidgetFacade(userName);
                return wfacade.UpdateWidgetSetup(_oldSetup, _newSetup);
            }
            catch (Exception ex)
            {
                //Console.WriteLine(ex.Message);
                return null;
            }
        }

        public Boolean MinimizeWidget(string userName, Int32 WidgetId)
        {
            try
            {
                WidgetFacade wfacade = new WidgetFacade(userName);
                return wfacade.MinimizeWidget(WidgetId);
            }
            catch (Exception ex)
            {
                //Console.WriteLine(ex.Message);
                return false;
            }
        }

        public Boolean MaximizeWidget(string userName, Int32 WidgetId)
        {
            try
            {
                WidgetFacade wfacade = new WidgetFacade(userName);
                return wfacade.MaximizeWidget(WidgetId);
            }
            catch (Exception ex)
            {
                //Console.WriteLine(ex.Message);
                return false;
            }
        }

        public Boolean FullScreenWidget(string userName, Int32 WidgetId)
        {
            try
            {
                WidgetFacade wfacade = new WidgetFacade(userName);
                return wfacade.FullScreenWidget(WidgetId);
            }
            catch (Exception ex)
            {
                //Console.WriteLine(ex.Message);
                return false;
            }
        }

        public Boolean DeleteWidget(string userName, Int32 WidgetId)
        {
            try
            {
                WidgetFacade wfacade = new WidgetFacade(userName);
                return wfacade.DeleteWidget(WidgetId);
            }
            catch (Exception ex)
            {
                //Console.WriteLine(ex.Message);
                return false;
            }
        }

        public Boolean UpdateWidgetState(string userName, Int32 WidgetId, string State)
        {
            try
            {
                WidgetFacade wfacade = new WidgetFacade(userName);
                return wfacade.UpdateWidgetState(WidgetId, State);
            }
            catch (Exception ex)
            {
                //Console.WriteLine(ex.Message);
                return false;
            }
        }

    }
}
